<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>父子组件传值</title>
		<script type="text/javascript" src="js/vue.js" ></script>
	</head>
	<body>
		<div id="root">
			<counter :count="2" @change="handlerChange"></counter>
			<counter :count="3" @change="handlerChange"></counter>
			{{total}}
		</div>
		<script>
			var counter = {
				props: ['count'],
				data: function() {
					return {
						number: this.count
					}
				},
				template: "<div @click='handlerClick'>{{number}}</div>",
				methods: {
					handlerClick: function() {
						this.number++;
						this.$emit("change", 1)
					}
				}
			}
			var vm = new Vue({
				el: "#root",
				data: {
					total: 5
				},
				components: {
					counter: counter
				},
				methods: {
					handlerChange: function(step) {
						this.total += step
					}
				}
			})
		</script>
	</body>
</html>
